/* 
** test other 
*/
#include <stdio.h>
#include <string.h>

static char * lcs_logname = "lcs_other";
static char lcs_logbuf[512];
static void lcs_testlog()
{
	int fp;
	
	fp = fopen( lcs_logname, "at" );
	if( !fp ) return;

	printf( "%s", lcs_logbuf );
	fprintf( fp, "%s", lcs_logbuf );
	
	fclose( fp );
}

/*
** test begin...
*/
int XN[256], NX[256];
void genlt()
{
	int i, j;
	
	XN[0] = 1;
	for (i = 1; i < 256; i++){
		j = ( XN[i-1] << 1) ^ XN[i-1];
		if ( j > 256 )	j ^= 283;            
		XN[i] = j;
	}
	
	NX[0] = NX[1] = 0;
	for (i = 1; i < 255; i++)	NX[XN[i]] = i;
}


int mul( int a, int b )
{
	if( a==0 || b==0 )	return 0;
	else	return XN[ (NX[a]+NX[b])%255 ];
}

int div( int a, int b )
{
	int x;
	if( a==0 )	return 0;
	if( b==0 )	return -1;
	x = NX[a]-NX[b] < 0 ? NX[a]-NX[b]+255 : NX[a]-NX[b];
	return XN[x];
}

void lcs_other()
{
	int i;
	unsigned char DEF = 2;
	unsigned char C[256], M[256], O[256];

	genlt();
	sprintf( (char*)C, "zhongguo shi shufa de haiyang !" );
	sprintf( lcs_logbuf, "%s\n", C );
	lcs_testlog();
	for( i=0; i<256; i++ ){
		M[i] = mul( DEF, C[i] );
	}
	sprintf( lcs_logbuf, "%s\n", M );
	lcs_testlog();
	for( i=0; i<256; i++ ){
		O[i] = div( M[i], DEF );
	}
	sprintf( lcs_logbuf, "%s\n", O );
	lcs_testlog();
}

